package com.tedu.servies;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tedu.mapper.OrderItemMapper;
import com.tedu.pojo.Order;
import com.tedu.mapper.OrderMapper;
import com.tedu.pojo.Cate;
import com.tedu.pojo.OrderItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServies {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderItemMapper orderItemMapper;

    public List<Order> getListByUserId(Integer id) {

        System.out.println(id);
        QueryWrapper wrapper = Wrappers.query();
        //用户id
        wrapper.eq("user_id", id);

        List<Order> orders = orderMapper.selectList(wrapper);
        System.out.println("ddddd");
        System.out.println(orders);
        return orders;

    }

    public List<OrderItem> getOrderItem(List<String> id){
        QueryWrapper<OrderItem> wrapper = Wrappers.query();
//        Map<String,Object> map = new HashMap<String, Object>();
        List<OrderItem> list = new ArrayList<OrderItem>();
        for (int i = 0; i < id.size(); i++) {
            wrapper.eq("order_id", id.get(i));
            List<OrderItem> orderItems = orderItemMapper.selectList(wrapper);
//            map.put("orderItems"+i,orderItems);
            list.addAll(orderItems);
        }
        System.out.println("server");
        System.out.println(list);
        return list;
    }
}
